﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace IndentationSplitter.Tests
{
    [TestClass]
    public class IndentedLineTests
    {
        [TestMethod, TestCategory("UnitTest")]
        [ExpectedException(typeof(FormatException))]
        public void GivenLineWithOnlyTabsFailes()
        {
            IndentedLine.GetLinesFromText(@"            ");
        }

        [TestMethod, TestCategory("UnitTest")]
        public void GivenATextWithIndentedHierarchyFindsLinesInOrder()
        {
            const string indentedStructure = @"level0
    level1
    level1
        level2
        level2
    level1
    level1
level0
    level1
        level2";

            var lines = IndentedLine.GetLinesFromText(indentedStructure);

            var expectedLevels = string.Join(string.Empty, indentedStructure
                .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(l => l.Trim().Replace("level", string.Empty)));

            var actualLevels = string.Join(string.Empty, lines.Select(l => l.Indentation.ToString()));

            Assert.AreEqual(expectedLevels, actualLevels);
        }
    }
}
